﻿#ifndef MAINWIDGET_H
#define MAINWIDGET_H

#include <QAbstractButton>
#include <QFrame>

namespace Ui {
class MainWidget;
}

class QMenu;
class QTreeWidgetItem;
class ChatRoom;
class NotifyLabel;

class MainWidget : public QFrame
{
    Q_OBJECT

public:
    explicit MainWidget(QWidget *parent = Q_NULLPTR);
    ~MainWidget();

    void setMaximizeButton(bool isMax);
    bool isTitle(const QPoint &pos) const;
    void readyToClose();

    void handle_trayIcon_menu(QMenu *menu);
    void handle_open_room(qint64 uniqueId, bool closeOldEvenNoNewRoom, bool shareCommand = false);
    void handle_contact_list(const QVariant &variant);
    void handle_org_list(const QVariant &variant);

    void handle_login_ack(QVariantHash &msg);
    void handle_change_state(QVariantHash &msg);
    void handle_recv_im(QVariantHash &msg);

    void handle_im_event(int cmd_type, QVariantHash &msg);
    void handle_channel_event(int cmd_type, QVariantHash &msg);
protected:
    void resizeEvent(QResizeEvent *e);
private slots:
    void button_close_clicked();
    void deleteChannelMessage(qint64 uniqueId);
    void showContact();

    void slot_local_video(qint64 room_id, qint64 user_id, QPixmap pix);
    void slot_remote_video(qint64 room_id, qint64 user_id, QPixmap pix);
    void slot_local_audio(qint64 room_id, qint64 user_id, int volume);
    void slot_remote_audio(qint64 room_id, qint64 user_id, int volume);

    void on_btn_channel_talk_clicked(bool checked);

    void on_btn_contact_list_clicked(bool checked);

    void on_btn_dispatch_clicked();

    void on_view_channel_talk_doubleClicked(const QModelIndex & index);

    void on_view_contact_list_itemDoubleClicked(QTreeWidgetItem *item, int column);

    void on_button_stacked_close_clicked();

    void on_stackedWidget_currentChanged();

    void on_edit_search_channel_returnPressed();

    void on_edit_search_contact_returnPressed();

private:
    void closeDynamicWithoutNew();
    void handle_call_room(qint64 rid, uchar times);
    void createWeb();
    qint64 openedUniqueId();
    Ui::MainWidget *ui;

    int login_state_;
    bool webCreated;
};

#endif // MAINWIDGET_H
